﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom;
using devtm.Editor.TypeSelector;

namespace devtm.Templates.Helpers
{


    public class MyProperty : CodePropertyReferenceExpression
    {


        public MyProperty() { }

        public MyProperty(CodeExpression targetObject, string propertyName) : base(targetObject, propertyName) { }

        public MyProperty(MyRef myRef, string propertyName, string typeName): this(myRef, propertyName) 
        {

            Type = new MyType(typeName);
            
        }

        public MyProperty(MyRef myRef, string propertyName, Type type)
            : this(myRef, propertyName)
        {

            Type = new MyType(type);

        }

        public MyProperty(MyRef myRef, string propertyName, MyType type)
            : this(myRef, propertyName)
        {

            Type = type;

        }


        public MyType Type { get; private set; }

        public CodeAssignStatement Set(CodeExpression code)
        {
            return new CodeAssignStatement(this, code);
        }

        //public static explicit operator MyRef(MyProperty property)
        //{
        //    return new MyRef(property.PropertyName, property.Type);
        //}


        public MyProperty Property(string propertyName, string typeName)
        {
            return new MyProperty(this, propertyName) { Type = new MyType(typeName) };
        }
        public MyProperty Property(string propertyName, BuildTypeExpression type)
        {
            return new MyProperty(this, propertyName) { Type = new MyType(type) };
        }

        public CodeMethodInvokeExpression Call(string methodName, params CodeExpression[] parameters)
        {
            return new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(this, methodName), parameters);
        }
    }


}
